<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    a{
        color: red;
    }
</style>
<body>
    <h3>你好，请<a href="login.html">登录</a></h3>
    <!-- <h1>欢迎，<span>xxx</span> </h1> -->
</body>
</html>
<script src="./axios.js"></script>
<script>
    var OH1 = document.querySelectorAll("h1")
    var oSpan = document.querySelector("span");

    //默认显示 亲，请登录， 欢迎xxx隐藏
    oH1[0].style.display = 'block'
    OH1[1].style.display = 'none'
    // 发送请求，如果登陆了，让 (欢迎xxx)显示，(亲，请登录)隐藏
    axios({
        method:"get",
        url:"http:/localhost:8888/users/info",
        params:{
            id:localStorage.geyItem("id")
        },
        //携带这个请求头，代表用户是登录过的
        headers:{
            "authorization":localStorage.getItem("token")
        }
    }).them(res => {
        console.log(res);
        if(res.data.code != 1){
            return;
        }
        oH1[0].style.display = 'none'
        oH1[1].style.display = 'block'
        oSpan.innerText = res.data.info.username;
    })
</script>